home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 6.7 KB | 252 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ClockFra.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Lonnie Millett
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef CLOCKFRA_H
- #include "ClockFra.h"
- #endif
-
- #ifndef CLOCKFAC_H
- #include "ClockFac.h"
- #endif
-
- #ifndef CLOCKPAR_H
- #include "ClockPar.h"
- #endif
-
- // ----- FrameWork Includes -----
-
- #ifndef FWUTIL_H
- #include <FWUtil.h>
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWTXTSHP_H
- #include <FWTxtShp.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _FRAME_
- #include <Frame.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _XMPSESSN_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _ARBITRAT_
- #include <Arbitrat.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <Quickdraw.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FONTS__)
- #include <Fonts.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTEDIT__)
- #include <TextEdit.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__SCRIPT__)
- #include <Script.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
- #include <TextUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #pragma segment cclockframe
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const short kClockMinimumSize = 120;
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::CClockFrame
- //----------------------------------------------------------------------------------------
- CClockFrame::CClockFrame()
- : FW_CFrame()
- {
- fClockPart = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::~CClockFrame
- //----------------------------------------------------------------------------------------
- CClockFrame::~CClockFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::InitClockFrame
- //----------------------------------------------------------------------------------------
- void CClockFrame::InitClockFrame(XMPFrame* xmpFrame, CClockPart* clockPart)
- {
- this->InitFrame(xmpFrame, clockPart);
-
- // ----- By default we put all of them -----
- AddToFocusSet(clockPart->GetMenuFocusToken());
- AddToFocusSet(clockPart->GetSelectionFocusToken());
-
- fClockPart = clockPart;
-
- // Calculate a default rectangle size for a digital clock
- /* Str255 digitalWidth;
- {
- FW_CAcquireASLMResourceAccess aq;
- GetIndString(digitalWidth, kClockPartStrings, kClockDigitalWidthString);
- }
-
- FW_CString32 tempStr;
- tempStr.ReplaceAll(digitalWidth);
- */
- FW_CString32 tempStr("12:59:59 MM");
-
- FW_CTextShape textShape(tempStr, FW_kZeroPoint, FW_kAscentLine);
- textShape->SetFontName(FW_kSystemFont);
- textShape->SetFontSize(ff(12));
- fDigitalClockRect = textShape->GetShapeBounds();
- fDigitalClockRect.Inset(ff(-3), ff(-3));
- fDigitalClockRect.Place(0,0);
-
- // ----- Set as Droppable -----
- this->SetDroppable(TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::GetNewFrameShape
- //----------------------------------------------------------------------------------------
- XMPShape* CClockFrame::GetNewFrameShape(FW_CFacet* facet)
- {
- FW_CGraphicContext gc(facet->GetXMPFacet());
-
- XMPRgnHandle frameRegion = NewRgn();
- FW_SPlatformRect frameRect;
-
- XMPShape* newFrameShape = ::NewXMPShape();
-
- if (fClockPart->GetClockType() == kAnalogClock)
- {
- XMPRgnHandle shapeRegion = this->GetXMPFrame()->GetFrameShape()->GetQDRegion();
- short size = (*shapeRegion)->rgnBBox.bottom - (*shapeRegion)->rgnBBox.top;
- if (size > (*shapeRegion)->rgnBBox.right - (*shapeRegion)->rgnBBox.left)
- size = (*shapeRegion)->rgnBBox.right - (*shapeRegion)->rgnBBox.left;
-
- if (size < kClockMinimumSize)
- size = kClockMinimumSize;
-
- SetRect(&frameRect, 0, 0, size, size);
- OpenRgn();
- FrameOval(&frameRect);
- CloseRgn(frameRegion);
- newFrameShape->SetQDRegion(frameRegion);
- }
- else
- {
- newFrameShape->SetRectangle(&fDigitalClockRect);
- }
-
- return newFrameShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::NewFacet
- //----------------------------------------------------------------------------------------
- FW_CFacet* CClockFrame::NewFacet(XMPFacet* xmpFacet)
- {
- CClockFacet* facet = new CClockFacet;
- facet->InitClockFacet(xmpFacet, this);
- return facet;
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::FacetAdded
- //----------------------------------------------------------------------------------------
- void CClockFrame::FacetAdded(FW_CFacet* facet)
- {
- FW_CFrame::FacetAdded(facet);
-
- this->RequestFrameShape(this->GetNewFrameShape(facet));
- this->UpdateUsedAndActiveShapes();
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::FacetRemoved
- //----------------------------------------------------------------------------------------
- void CClockFrame::FacetRemoved(FW_CFacet* facet)
- {
- FW_CFrame::FacetRemoved(facet);
-
- this->RequestFrameShape(this->GetNewFrameShape(facet));
- this->UpdateUsedAndActiveShapes();
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- void CClockFrame::FrameShapeChanged()
- {
- this->RequestFrameShape(this->GetNewFrameShape(this->GetActiveFacet()));
- this->UpdateUsedAndActiveShapes();
-
- XMPShape oldShape;
- this->GetFrameShape(&oldShape);
- this->Invalidate(&oldShape);
- this->GetXMPFrame()->InvalidateActiveBorder();
- }
-
- //----------------------------------------------------------------------------------------
- // CClockFrame::UpdateClock
- //----------------------------------------------------------------------------------------
- void CClockFrame::UpdateClock(unsigned long tickCount)
- {
- FW_CFrameFacetIterator facets(this);
- CClockFacet* clockFacet;
- while (!facets.IsDone())
- {
- clockFacet = (CClockFacet*)facets.CurrentItem();
- FW_CGraphicContext gc(clockFacet->GetXMPFacet());
-
- if (fClockPart->GetClockType() == kAnalogClock)
- clockFacet->UpdateAnalogClock(&gc, tickCount);
- else
- clockFacet->UpdateDigitalClock(&gc, tickCount);
-
- facets.Next();
- }
- }
-
-